$(function(){
	var recoedType = 0;
	var usertype = $('#usertype option:selected') .val();//选中的值
	var phone=$("#phone").val();//用户昵称
	//自动加载
	loadData(recoedType,0,usertype,phone,1);
});


function loadData(recoedType,withdrawStatus,usertype,phone,pageNo){
	var id="",givePerson="",receivePerson="" ,orderType="",orderNumber="",pageSize = 8 ,html="",index=0,realName="",money="",transactionNum="",payType="",gmtDatetime="" ,totalMoney=0.00;
		//获取用户信息列表
		$("#thislist").html("");
	  $.ajax({  
        type : "GET",  
        url : urlcore + "/api/cashRecord/cashRecordList?recoedtype="+recoedType+"&withdrawStatus="+withdrawStatus+"&usertype="+usertype+"&phone="+phone+"&pageNum="+pageNo+"&pageSize="+pageSize, 
        dataType : "json",
        headers:{"Content-Type":"application/json;charset=UTF-8"},
        success: function(data) {//data是返回的hash,key之类的值，key是定义的文件名 
        	var da=data.data.list;
        	var totalMoney2=0.00;
        	if(data.success==true){
        		for(var i=0;i<da.length;i++ ){
        			++index;
        			id=da[i].id;       		
        			//获取总金额      			
        			if(da[i].money!=null){
        				totalMoney+=parseFloat(da[i].money);
        			}
        			totalMoney2=totalMoney.toFixed(2);
        			realName=da[i].user.realName;
        			userType=da[i].user.userType==2?"骑手":da[i].user.userType==3?"商家":"用户";
					
					givePerson=da[i].givePerson;
					if(givePerson==0){
        				givePerson="平台";
        			}else if(givePerson==1){
        				givePerson="商家";
        			}else if(givePerson==2){
        				givePerson="骑手";
        			}else if(givePerson==null){
        				givePerson="";
        			}
					receivePerson=da[i].receivePerson;
					if(receivePerson==0){
        				receivePerson="平台";
        			}else if(receivePerson==1){
        				receivePerson="商家";
        			}else if(receivePerson==2){
        				receivePerson="骑手";
        			}else if(receivePerson==null){
        				receivePerson="";
        			}       			
					orderType=da[i].orderType;
					if(orderType==1){
        				orderType="配送订单";
        			}else if(orderType==2){
        				orderType="商城订单";
        			}else if(orderType==3){
        				orderType="其他";
        			}else if(orderType==4){
        				orderType="保险";
        			}else if(orderType==5){
        				orderType="处罚";
        			}
        			
					orderNumber=da[i].orderNumber;
					if(orderNumber==null){
						orderNumber="无";
					}
        			money=da[i].money;
        			if(money==null){
						money="";
					}
        			transactionNum=da[i].transactionNum;    
          html += '<tr class="footable-even" style="display: table-row;">'+
            	 '	<td class="footable-visible">'+index+'</td>'+
            	'	<td class="footable-visible">'+givePerson+'</td>'+
				'	<td class="footable-visible">'+receivePerson+'</td>'+            				
				'	<td class="footable-visible">'+money+'</td>'+
				'	<td class="footable-visible">'+orderType+'</td>'+
				'	<td class="footable-visible">'+orderNumber+'</td>'+
				'	<td class="footable-visible">'+
						'	<a class="btn btn-primary btn-xs" href="transaction_details.html?id='+id+'"> 详细</a>'+
				'</td>'+
				'</tr>';
        		}
        		$("#thislist").append(html);
        		$("#totalMoney").html(totalMoney2);
        		$('#thiscount').text(data.data.total);
        		$("#pager").pager({
					pagenumber: pageNo, 
					pagecount:data.data.pages,
					totalcount:data.data.total,
					buttonClickCallback: PageClick
				}); 
            }
        },
        error:function(){  
            alert("失败");  
        }  
    }); 
	
}
//回调函数  
	PageClick = function(pageclickednumber) {  
		var recoedType = 0;//选中的值
		var usertype = $('#usertype option:selected') .val();//选中的值
		var phone=$("#phone").val();//用户昵称
	    loadData(recoedType,0,usertype,phone,pageclickednumber)
	}
	




//搜索
function searchuser() {
		var recoedType = 0;//选中的值
		var usertype = $('#usertype option:selected') .val();//选中的值
		var phone=$("#phone").val();//用户昵称
	    loadData(recoedType,0,usertype,phone,1)
}

/**
 * 审核通过
 */
function pass(id){
	$.ajax({
        url: urlcore + "/api/cashRecord/setPass?id="+id,
        type: "get",
        dataType: 'json',
        contentType: "application/json;charset=utf-8",
        success:function(data){
            if (data.success == true) {
            	location.reload();
            } else if (data.code == 'OVERTIME'){
                    var thisUrl = window.location.href;
                    if (thisUrl.indexOf('login.html') <= -1) {
                        top.window.location.href="login.html";
                    }
                } else {
                    alert(data.msg);
                }
        },
        error:function() {
            /* Act on the event */
            alert("error");
        }
    });
}

/**
 * 审核失败
 */
function fail(id){
	$.ajax({
        url: urlcore + "/api/cashRecord/setFail?id="+id,
        type: "get",
        dataType: 'json',
        contentType: "application/json;charset=utf-8",
        success:function(data){
            if (data.success == true) {
            	location.reload();
            } else if (data.code == 'OVERTIME'){
                    var thisUrl = window.location.href;
                    if (thisUrl.indexOf('login.html') <= -1) {
                        top.window.location.href="login.html";
                    }
                } else {
                    alert(data.msg);
                }
        },
        error:function() {
            /* Act on the event */
            alert("error");
        }
    });
}